<?php
require 'inc_security.php';
$id_field = 'imu_id';
$myform = new generate_form();
$action = getValue('action','str','POST','');
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="vi" lang="vi" xmlns:og="http://ogp.me/ns#" xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?=$load_header?>
</head>
<body>
<div class="module_header bold fix"><?=$module_name?></div>
<div id="wrapper">
<?
if($action == 'execute'){
   $bg_errorMsg .= $myform->checkdata();
   $upload = new upload('imu_image',$bg_filepath,$bg_extension,$limit_size);
   $filename = $upload->file_name;
   if($filename){
      $myform->add('imu_image','filename',0,1,'');
      $myform->add('imu_module','bg_table',0,1,'');
      /*foreach($arr_resize as $type => $arr){
      resize_image($bg_filepath, $filename, $arr["width"], $arr["height"], $arr["quality"], $type);
   }*/
   $bg_errorMsg .= $upload->show_warning_error();
   if($bg_errorMsg == ''){
   $myform->addTable('images_upload');
   $myform->removeHTML(0);
      $db_insert = new db_execute_return();
      $last_id = $db_insert->db_execute($myform->generate_insert_SQL());
      //Add seo meta
      redirect('m8_upload.php');
   }
   }
}
   $list = new dataGrid('imu_id',30);
   $list->add('imu_image','Ảnh','string',1,0, 'width="120px"');
   $list->add('imu_module','Đường dẫn ảnh','string',0,0, 'width="120px"');
   $list->add('','Delete','delete');
   $db_count = new db_count('SELECT count(*) as count 
                               FROM images_upload
                               WHERE 1 '.$list->sqlSearch().' AND imu_module ="'.$bg_table.'"
                               ');
   $total = $db_count->total;unset($db_count);
   
   $db_listing = new db_query('SELECT * 
                               FROM images_upload
                               WHERE 1 '.$list->sqlSearch().' AND imu_module ="'.$bg_table.'"
                               ORDER BY '.$list->sqlSort().' imu_id DESC 
                               '.$list->limit($total));
   $total_row = mysql_num_rows($db_listing->result);
?>
   <?print_error_msg($bg_errorMsg)?>
   <?php $form = new form();?>
   <?=$form->form_open()?>
   
   <?=$form->getFile(array('label'=>'Ảnh','title'=>'Ảnh','name'=>'imu_image','id'=>'imu_image'))?>
   
   <?=$form->form_action(array('label'=>array('Thêm mới','Nhập lại'),'type'=>array('submit','reset')))?>
   <?=$form->form_close()?>
   
   <?=$list->showHeader($total_row)?>
   <?php
   $i = 0; 
   ?>
   <?php while($row = mysql_fetch_assoc($db_listing->result)){
     $i++;
   ?>
   <?=$list->start_tr($i,$row[$id_field])?>
   <td class="center">
     <div class="img_thumb">
         <img src="<?=$bg_filepath?><?=$row['imu_image']?>" alt="Không có ảnh"/>
     </div>
   
   </td>
   <td>
      <?=$domain.'/pictures/'.$bg_table.'/'.$row['imu_image']?>
   </td>
   
   <?=$list->showDeleteImage($row[$id_field])?>
   <?=$list->end_tr()?>
   <?}?>
   <?=$list->showFooterImages()?>
</div>